﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Asd.MP.Entity;
using Asd.MP.Utility;


namespace MobilePlatform.Controllers
{


    public class SystemInfoController : BaseController
    {


        
        public ActionResult Index()
        {
            return RedirectToAction("SerialList");
        }

        public ActionResult SerialList(int pageIndex = 1, string mobile = "", string account = "")
        {
            mobile = mobile.Trim();
            account = account.Trim();

            int totalRows = 0;
            int pageSize = 5;

            ViewData["SerialNoStatus"] = _systemInfoBal.GetSerailStatusList();
            var viewModel = _systemInfoBal.GetSerailNoList(pageIndex, pageSize, mobile, account, out totalRows);
            ViewData["Pager"] = this.CreatePager(Url.Action("SerialList", new { pageIndex = "{0}", mobile = mobile, account = account }), totalRows, pageIndex, pageSize);
            return View(viewModel);
        }

        public ActionResult NewSerailNo()
        {
            return RedirectToAction("SerilaNoPost", new { sn = string.Empty });
        }

        public ActionResult SerilaNoPost(string sn = "")
        {
            ViewData["SerialNoStatus"] = _systemInfoBal.GetSerailStatusList();
            return View(_systemInfoBal.GetSerailBySn(sn));
        }


        [HttpPost]
        [OutputCache(Duration = 1)]
        public ActionResult SerilaNoPost(SerialNoEntity serial, int a = 0)
        {

            MessageHelper msg = new MessageHelper(MessageStatus.Error);
            msg.AddBody("一个或多个错误导致操作失败");
            msg.Required(serial.EMPAccount, "用户账户不能为空");
            if (msg.IsValid)
            {
                if (_systemInfoBal.SaveSerail(serial) != 1)
                {
                    msg.AddMessage("对不起,该手机号码已经被其他用户注册");
                }
                else
                {
                    msg.AddBody(MessageStatus.Ok, "操作成功", string.Empty);
                    msg.DefaultOperate(string.Format("javascript:{0}", JavaScriptHelper.Close()));
                }
            }
            return MessageResult(msg.CreateMessage());
        }
    }
}
